// DriveNotes. Copyright (c) 2011, Andrei Senchuk. All rights reserved.
package net.taviscaron.drivenotes.web.converter;

import java.util.Map;
import net.taviscaron.drivenotes.shared.model.entity.Car;
import net.taviscaron.drivenotes.web.util.ParamUtils;

/**
 *
 * @author taviscaron
 */
public class CarConverter extends FormConverter<Car> {

    @Override
    public Car convert(Map params, String prefix) throws InvalidFormException {
        try {
            Car car = new Car();
            car.setId(ParamUtils.parseLongParam(params, "id", prefix));
            car.setBrand(ParamUtils.parseStringParam(params, "brand", prefix));
            car.setModel(ParamUtils.parseStringParam(params, "model", prefix));
            car.setYear(ParamUtils.parseIntParam(params, "year", prefix));
            car.setEngineType(ParamUtils.parseEngineTypeParam(params, "engineType", prefix));
            car.setEngineVolume(ParamUtils.parseIntParam(params, "engineVolume", prefix));
            car.setColor(ParamUtils.parseIntParam(params, "color", prefix));
            car.setOdometrValue(ParamUtils.parseIntParam(params, "odometrValue", prefix));
            car.setOdometrFollowed(ParamUtils.parseBoolParam(params, "odometrFollowed", prefix));
            return car;
        } catch (IllegalArgumentException e) {
            throw new InvalidFormException();
        }
    }

}
